using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace SpoonStun.Message
{
	class PingMessage : IStunMessage
	{
		private static int _count;
		private int _id = _count++;
		private TypeValue _type = TypeValue.Request;

		public enum TypeValue : byte { Request, Response }

		public int MsgId
		{
			get { return 2; }
		}

		public int Id
		{
			get { return _id; }
			set { _id = value; }
		}

		public TypeValue Type
		{
			get { return _type; }
			set { _type = value; }
		}

		public void SetBytes(byte[] data)
		{
			MemoryStream stream = new MemoryStream(data);
			BinaryReader br = new BinaryReader(stream);

			Id = br.ReadInt32();
			Type = (TypeValue) br.ReadByte();
		}

		public byte[] GetBytes()
		{
			MemoryStream stream = new MemoryStream();
			BinaryWriter bw = new BinaryWriter(stream);

			bw.Write(Id);
			bw.Write((byte)Type);

			return stream.ToArray();
		}
	}
}
